unit VendeItem;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Mask, Buttons;

type
  TFormVendeItem = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    GroupBox1: TGroupBox;
    GroupBox2: TGroupBox;
    Edit1: TEdit;
    Edit2: TEdit;
    RBInteira: TRadioButton;
    RBFracao: TRadioButton;
    GroupBox3: TGroupBox;
    RB_2Decimais: TRadioButton;
    RB_3Decimais: TRadioButton;
    RB_Desconto_valor: TRadioButton;
    RB_Desconto_percentual: TRadioButton;
    BitBtn1: TBitBtn;
    ComboBox1: TComboBox;
    MaskEdit1: TMaskEdit;
    MaskEdit2: TMaskEdit;
    MaskEdit3: TMaskEdit;
    procedure BitBtn1Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure RBInteiraClick(Sender: TObject);
    procedure RBFracaoClick(Sender: TObject);
    procedure RB_2DecimaisClick(Sender: TObject);
    procedure RB_3DecimaisClick(Sender: TObject);
    procedure RB_Desconto_percentualClick(Sender: TObject);
    procedure RB_Desconto_valorClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FormVendeItem: TFormVendeItem;

implementation

uses principal, funcoesapoio, declaracoes;

{$R *.dfm}

procedure TFormVendeItem.BitBtn1Click(Sender: TObject);
begin
        FormPrincipal.CodigoItem:=Edit1.Text;
        FormPrincipal.DescricaoItem:=Edit2.Text;
        FormPrincipal.AliquotaItem:=ComboBox1.Text;

        if RBInteira.Checked then FormPrincipal.TipoQtdeItem:='I'
        else FormPrincipal.TipoQtdeItem:='F';
        FormPrincipal.QtdeItem:=MaskEdit1.Text;

        if rb_2Decimais.Checked Then FormPrincipal.DecimaisItem:=2
        else FormPrincipal.DecimaisItem:=3;
        FormPrincipal.UnitarioItem:=MaskEdit2.text;

        if Rb_Desconto_valor.checked then FormPrincipal.TipoDescontoItem:='$'
        else FormPrincipal.TipoDescontoItem:='%';
        FormPrincipal.DescontoItem:=MaskEdit3.Text;

        if not ((FormPrincipal.CodigoItem = #0) or (FormPrincipal.DescricaoItem = #0) or
                (FormPrincipal.AliquotaItem = #0) or (FormPrincipal.TipoQtdeItem = #0) or
                (FormPrincipal.QtdeItem = #0) or (FormPrincipal.DecimaisItem = 0) or
                (FormPrincipal.UnitarioItem = #0) or (FormPrincipal.TipoDescontoItem = #0) or
                (FormPrincipal.DescontoItem = #0)) then begin
                FormPrincipal.Statusbar1.Panels[0].Text:='Vende Item'; WaitProcess;

                Resposta:=ECF_VendeItem(FormPrincipal.CodigoItem, FormPrincipal.DescricaoItem, FormPrincipal.AliquotaItem, FormPrincipal.TipoQtdeItem, FormPrincipal.QtdeItem, FormPrincipal.DecimaisItem, FormPrincipal.UnitarioItem, FormPrincipal.TipoDescontoItem, FormPrincipal.DescontoItem);

                FormPrincipal.Memo1.Lines.Add('');
                FormPrincipal.Memo1.Lines.Add('VendeItem:'+inttostr(Resposta));
                FormPrincipal.Memo1.Lines.Add('');
                VerificaRetornoFuncao(Resposta);
                Refresh;
        end;
end;

procedure TFormVendeItem.FormShow(Sender: TObject);
var i:integer;
begin
        CapturaDadosProgamadosECF(1); // Captura Alíquotas ICMS
        for i:=1 to 20 do begin
                if not (Aliquotas_ICMS_ISS[i].taxa='') then
                        Combobox1.Items.ADD(Aliquotas_ICMS_ISS[i].taxa);
        end;
        Combobox1.Items.ADD('FF');
        Combobox1.Items.ADD('II');
        Combobox1.Items.ADD('NN');
        Combobox1.Items.ADD('FS');
        Combobox1.Items.ADD('IS');
        Combobox1.Items.ADD('NS');
        ComboBox1.Text:=Aliquotas_ICMS_ISS[1].taxa;
        Edit1.Setfocus;
end;

procedure TFormVendeItem.RBInteiraClick(Sender: TObject);
begin
        MaskEdit1.MaxLength:=4;
        MaskEdit1.EditMask:='9999';
        MaskEdit1.Text:='0001';
end;

procedure TFormVendeItem.RBFracaoClick(Sender: TObject);
begin
        MaskEdit1.MaxLength:=7;
        MaskEdit1.EditMask:='9999,999';
        MaskEdit1.Text:='0001,000';

end;

procedure TFormVendeItem.RB_2DecimaisClick(Sender: TObject);
begin
        MaskEdit2.MaxLength:=8;
        MaskEdit2.EditMask:='999999,99';
        MaskEdit2.Text:='000001,00';
end;

procedure TFormVendeItem.RB_3DecimaisClick(Sender: TObject);
begin
        MaskEdit2.MaxLength:=8;
        MaskEdit2.EditMask:='99999,999';
        MaskEdit2.Text:='00001,000';

end;

procedure TFormVendeItem.RB_Desconto_percentualClick(Sender: TObject);
begin
        MaskEdit3.MaxLength:=4;
        MaskEdit3.EditMask:='9999';
        MaskEdit3.Text:='0100';

end;

procedure TFormVendeItem.RB_Desconto_valorClick(Sender: TObject);
begin
        MaskEdit3.MaxLength:=9;
        MaskEdit3.EditMask:='999999,99';
        MaskEdit3.Text:='000001,00';

end;

procedure TFormVendeItem.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
        HabilitaDesabilitaItensMenu(1);// Habilita os menus
        FormPrincipal.cursor:=crDefault;
end;

end.
